package com.hm.health.entity;

import androidx.annotation.NonNull;

import com.goodix.comsdk.RomaDevice;

/**
 *
 * @author chenshi
 * @date 2017/1/6
 */
public class BleDevicesInfo extends RomaDevice implements Cloneable, Comparable {
    private int mValue;
    private int mType;

    public BleDevicesInfo() {
        this(RomaDevice.DEVICE_NAME_DEFAULT, RomaDevice.DEVICE_ADDR_DEFAULT);
    }

    public BleDevicesInfo(int deviceType, String deviceName,
                          String deviceAddress, int rssi, String description) {
        super(deviceType, deviceName, deviceAddress);
        setRSSI(rssi);
    }

    @Override
    public Object clone() {
        BleDevicesInfo bleDevicesInfo = null;
        try {
            bleDevicesInfo = (BleDevicesInfo)super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return bleDevicesInfo;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof BleDevicesInfo) {
            BleDevicesInfo devicesInfo = (BleDevicesInfo)o;
            boolean isSameDevice = devicesInfo.getDeviceAddress().equals(getDeviceAddress()) &&
                    devicesInfo.getDeviceName().equals(getDeviceName());
            return isSameDevice;
        } else {
            return false;
        }
    }

    public BleDevicesInfo(String mStrDescription, String mDeviceAddress) {
        super(RomaDevice.DEVICE_TYPE_BLE, mStrDescription, mDeviceAddress);
    }

    public int getValue() {
        return mValue;
    }

    public void setValue(int value) {
        mValue = value;
    }

    public int getType() {
        return mType;
    }

    public void setType(int type) {
        mType = type;
    }

    public static BleDevicesInfo create(RomaDevice device) {
        BleDevicesInfo devicesInfo = new BleDevicesInfo(device.getDeviceType(),
                device.getDeviceName(), device.getDeviceAddress(), device.getRSSI(),"");
        device.setConnected(device.isConnected());
        return devicesInfo;
    }

    @Override
    public int compareTo(@NonNull Object o) {
        if (null != o && o instanceof BleDevicesInfo) {
            BleDevicesInfo d = (BleDevicesInfo) o;
            return d.getRSSI() - getRSSI();
        }
        return 0;
    }
}
